﻿using Business.WPF;
using DataAccess.Exceptions;
using Model;
using Presenters.WPF.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Presenters.WPF
{
    public class NewSubjectPresenter
    {
        public INewSubject view { get; set; }
                

        public NewSubjectPresenter(INewSubject view)
        {
            this.view = view;            
        }

        public bool SubmitValidationCreditsText()
        {
            try
            {
                Business.Tools.ValidationText.isNumber(this.view.credits.ToString(), "Creditos");
                return (true);
            }
            catch (Exception ex)
            {
                this.view.message = ex.Message;
            }
            return (false);
        }

        public void SubmitNewSubject()
        {
            try
            {
                NewSubjectManager ns = new NewSubjectManager();
                ns.newSubject(this.view.nameSubject, this.view.acronym, this.view.status, this.view.credits, this.view.description);
                this.view.message = "Se agregó correctamente la materia: " + this.view.acronym;
            }
            catch (ValidationException v_ex)
            {
                this.view.message = v_ex.Message;
            }
            catch (BusinessException b_ex)
            {
                this.view.message = b_ex.Message;
            }
            catch (Exception ex)
            {
                this.view.message = "Error -> " + ex.Message;
            }
        }

        public void SubmitModifySubject()
        {
            try
            {
                NewSubjectManager ns = new NewSubjectManager();
                ns.modifySubject(this.view.code, this.view.nameSubject, this.view.acronym, this.view.status, this.view.credits, this.view.description);
                this.view.message = "Se modificó correctamente la materia: " + this.view.acronym;
            }
            catch (ValidationException v_ex)
            {
                this.view.message = v_ex.Message;
            }
            catch (BusinessException b_ex)
            {
                this.view.message = b_ex.Message;
            }
            catch (Exception ex)
            {
                this.view.message = "Error -> " + ex.Message;
            }
        }
    }
}
